import { createRouter, createWebHistory } from 'vue-router'
import IndexView from '../views/IndexView.vue'
import LoginView from '../views/LoginView.vue'
import MainView from '../views/MainView.vue'
import RemindView from '../views/remind/RemindView.vue'

const routes = [
  {
    path: '/',
    name: 'index',
    component: IndexView
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView
  },
  {
    path: '/main',
    name: 'main',
    component: MainView
  },
  {
    path: '/remind',
    component: RemindView
  },
  {
    path: '/remindEdit',
    name: 'remindEdit',
    component: () => import('@/views/remind/RemindEditView.vue')
  },
  {
    path: '/remindAdd',
    name: 'remindAdd',
    component: () => import('@/views/remind/RemindAddView.vue')
  },
  {
    path: '/remindList',
    name: 'remindList',
    component: () => import('@/views/remind/RemindListView.vue')
  },
  {
    path: '/hotVideo',
    name: 'hotVideo',
    component: () => import('@/views/hotVideo/index.vue')
  },
  {
    path: '/douyinVideo',
    name: 'douyinVideo',
    component: () => import('@/views/douyinVideo/index.vue')
  },
  {
    path: '/etfMedian',
    name: 'etfMedian',
    component: () => import('@/views/etf/index.vue')
  },
  {
    path: '/canteenOrder',
    name: 'canteenOrder',
    component: () => import('@/views/canteen/index.vue')
  },
  {
    path: '/laji',
    name: 'laji',
    component: () => import('@/views/lamp/index.vue')
  },
  {
    path: '/torrent',
    name: 'torrent',
    component: () => import('@/views/torrent/index.vue')
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  if (!to.matched.length) {
    next({ name: 'index' }) // 跳转到首页
  } else {
    next()
  }
})

export default router
